package org.domeos.framework.api.biz.storage.impl;

import java.util.List;

import org.domeos.framework.api.biz.base.impl.BaseBizImpl;
import org.domeos.framework.api.biz.storage.StorageBiz;
import org.domeos.framework.api.mapper.domeos.storage.StorageMapper;
import org.domeos.framework.api.mapper.domeos.storage.VolumeDeployMapper;
import org.domeos.framework.api.model.storage.Storage;
import org.domeos.framework.api.model.storage.VolumeDeployMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StorageBizImpl extends BaseBizImpl implements StorageBiz {
	
	@Autowired
	StorageMapper storageMapper;
	
	@Autowired
	VolumeDeployMapper volumeDeployMapper;

	@Override
	public long createStorage(Storage storage) {
		return storageMapper.insertStorage(storage, storage.toString());
	}

	@Override
	public void updateStorage(Storage storage) {
		storageMapper.updateStorage(storage, storage.toString());
	}

	@Override
	public void deleteStorage(int id) {
		super.removeById("storage", id);
		
	}

	@Override
	public List<Storage> listStorageByClusterId(int clusterId) {
		return storageMapper.listStorageByClusterId(clusterId);
	}

	@Override
	public Storage getStorageById(int id) {
		return super.getById("storage", id, Storage.class);
	}

	@Override
	public Storage getStorageByName(String name) {
		return storageMapper.getStorageByName(name);
	}

	@Override
	public List<Storage> getStorageByPathAndServer(String path, String server) {
		return storageMapper.listStorageByPathAndServer(path, server);
	}

	@Override
	public void addVolumeVersionMount(VolumeDeployMap volumeDeployMap) {
		volumeDeployMapper.addVolumeVersionMount(volumeDeployMap);
	}

	@Override
	public int getCountDeployById(int id) {
		return volumeDeployMapper.getCountMapsByVolumeId(id);
	}

	@Override
	public List<VolumeDeployMap> getDeployInstanceById(int id) {
		return volumeDeployMapper.getMapsByVolumeId(id);
	}

	@Override
	public void removeVolumeVersionMapByDeployId(int id) {
		volumeDeployMapper.removeVolumeVersionMapByDeployId(id);
	}

	
}
